requirejs([ "text!myFramework/ui/ScrollView.stache" ], function(tpl) {
	can.Component.extend({
		tag : "scrollview",

		template : can.stache(tpl),
		viewModel : function(attrs,parentScope,el){
			
			//获取page对象的viewModel,组合组件从上层组件获取root,顶层组件的parentScope为root
			var _root=parentScope.attr("root")==undefined?parentScope:parentScope.attr("root");
			//获取页面对象
			var _page=_root.attr("page");
			//组件可以通过属性data重设数据值对象
			//组件可以通过属性data重设数据值对象
			var _contextName=attrs.context||"";
			var _data=can.getObject(_contextName,parentScope.attr("data")||_root.attr("data"));
			
			return {
				id:el.getAttribute("id"),
				contextName:_contextName,
				name:undefined,
				title:undefined,
				height:el.getAttribute("height"),
				page:_page,
				data:_data,
				root:_root
			};
		},
		events:{
			"inserted" :function(el,ev){
				
				var section = el.find("section").eq(0),
					div = section.find("div").eq(0);
					
				var wrapH = el.viewModel().height,//容器高度
					documentH = div.height(),//文档高度
					data = el.viewModel().context,
					data = data.substring(0,1).toUpperCase()+data.substring(1,data.length);
				var up = MF.getCurrentPage().viewModel.page["on"+data+"Up"],
					down = MF.getCurrentPage().viewModel.page["on"+data+"Down"];
				section.listenScroll({
					listenScroll:function(isInScroll, scrollDirection, scrollTop){

						if(scrollDirection == "down"){
							
							if(scrollTop == documentH-wrapH){
								
								var timer = setTimeout(function(){
									
									if(down) 
									down();
								},100);
								

							}
						}else if(scrollDirection == "up"){
							if(scrollTop == 0){
								
								var timer = setTimeout(function(){
									if(up) 
									up();
									
								},100);
							}
						}
					}
				})
			}
		}
	});
});